#ifndef SOCKET_H
#define SOCKET_H

#include <SDL/SDL_net.h>
#include <string>
#include <list>
using namespace std;

/*
  A Generic socket
  */
class Socket
{
public:
	Socket(int port); // For listening socket
	Socket(string hostname, int port);
	Socket(TCPsocket sock);
	~Socket();

	static void Init();
	static void Shutdown();

	bool Send(u_int8_t *buffer, size_t len);
	bool Recv(u_int8_t *buffer, size_t &len, bool wait = false);
	// For listening
	Socket* Accept();

	bool Ok() const { return mSocket; }
private:
	TCPsocket			mSocket;
	IPaddress			mIP;
	SDLNet_SocketSet	mSocketSet;
};

#endif // SOCKET_H
